<!DOCTYPE html>
<html lang="en">

<head>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box1 {
            margin: 20px 0;
        }


        .a {

            background-color: #ff0000;
        }


        .b {
            background-color: #008000;
        }


        .c {

            background-color: #000000;
        }

        body {
            width: 100%;
            height: 600px;
        }

        p {
            width: 15px;
            height: 15px;
            margin-top: 8px;
            background-color: #fff;
            display: none;
        }

        .bg {
            display: block;
        }

        .box2 {
            width: 100%;
            display: flex;
            margin-top: 20px;

        }

        ul {
            display: flex;
        }

        li {
            text-align: center;
            padding: 5px 50px;
            border: 1px solid #008000;
            list-style: none;
            text-align: center;
            color: #008000;
        }

        .child {
            float: left;
            width: 30px;
            height: 30px;
            margin-left: 20px;
            display: flex;
            justify-content: center;
            text-align: center;
        }

        .box1 div:nth-child(1) {
            background-color: #ff0000;
        }

        .box1 div:nth-child(2) {
            background-color: #008000;
        }

        .box1 div:nth-child(3) {
            background-color: #000000;
        }
    </style>
</head>

<body>
    <header class="box1">
        <div class="child">
            <p id="p1"></p>
        </div>
        <div class="child">
            <p id="p2"></p>
        </div>
        <div class="child">
            <p id="p3"></p>
        </div>
    </header>
    <div class="box2">
        <ul>
            <li>新闻</li>
            <li>娱乐</li>
            <li>体育</li>
            <li>电影</li>
            <li>音乐</li>
            <li>旅游</li>
        </ul>
    </div>
</body>

<script>

    let header = document.getElementsByClassName('box1')[0]

    let child = document.getElementsByClassName('child')

    
    let background = ['#ff0000', '#008000', '#000000']
    var bg = ['pink', 'yellow', '#ccc']

    let list = document.getElementsByTagName('li')



    Array.from(child).forEach((el, index) => {
        el.onclick = function (e) {
            Array.from(child).forEach(el => {
                el.children[0].style.display = 'none'
            })

            this.children[0].style.display = 'block'

            Array.from(list).forEach(liEle => {
                liEle.style.backgroundColor = background[index]
            })
            document.body.style.backgroundColor = bg[index]

        }

    })




</script>

</html>